<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left">
          <Breadcrumb />
        </div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          @row-click="edit"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <!--          <el-table-column type="selection" align="center" />-->
          <el-table-column label="状态" min-width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.status=='2'" class="status_space adequate_space">
                <svg-icon icon-class="通过" />
                <span> 全部收款 </span>
              </div>
              <div v-if="scope.row.status=='1'" class="status_space under_execution">
                <svg-icon icon-class="执行中" />
                <span> 部分收款 </span>
              </div>
              <div v-if="scope.row.status=='0'" class="status_space pending_payment">
                <svg-icon icon-class="待收款" />
                <span> 待收款 </span>
              </div>
            </template>
          </el-table-column>
          <Column
            v-for="(column,index) in tableColumns"
            :key="index"
            :prop="column.prop"
            :is-show="column.isShow"
            :label="column.label"
            :sortable="column.sortable"
            :width="column.width"
          />
          <el-table-column
            label="附件"
            min-width="80"
          >
            <template slot-scope="scope">
              <FileManage
                :file-names="scope.row.fileName"
                :file-real-names="scope.row.fileRealName"
                :file-urls="scope.row.fileUrl"
                :readonly="true"
                class="accessory"
                @fileName="setFileName"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list, remove, getInfo } from '@/api/receivableAndPayable/receivableAndPayableManage/additionalReceipt'
import { getDictSelects } from '@/api/common/common'
import AddOrUpdate from './addOrUpdate'
import ShowMaterialDetail from '@/views/receivableAndPayable/additionalReceipt/showAdditionalReceipt'
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '其他收款单', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [
        // 表格常规字段（初始值）
        { prop: 'code', label: '收款单号' },
        { prop: 'receiptByName', label: '制单人员', canOrder: false },
        { prop: 'receiptTime', label: '制单日期' },
        { prop: 'payee', label: '收款方', canOrder: false },
        { prop: 'incomeTypeCodeName', label: '收款类型', canOrder: false },
        { prop: 'saleOrderCode', label: '销售订单' },
        { prop: 'taxAllPrice', label: '含税总金额' },
        { prop: 'remark', label: '备注', canOrder: false }
      ],
      defaultSearchColumns: [
        // 搜索区常规字段（初始值）
        { prop: 'code', label: '收款单号', type: 'input' },
        { prop: 'receiptByName', label: '制单人员', type: 'input' },
        { prop: 'receiptTime', label: '制单日期', type: 'time' },
        { prop: 'payee', label: '收款方', type: 'input' },
        { prop: 'saleOrderCode', label: '销售订单', type: 'input' },
        { prop: 'incomeTypeCode', label: '收款类型', type: 'dict', optionsName: 'typeList' }
      ],
      showKey: [
        {
          name: '基本信息',
          columns: [
            { type: 'form', name: '收款单号', key: 'code' },
            { type: 'form', name: '制单人员', key: 'receiptByName' },
            { type: 'form', name: '制单日期', key: 'receiptTime' },
            { type: 'form', name: '客户名称', key: 'customerName' },
            { type: 'form', name: '销售订单', key: 'saleOrderCode' },
            { type: 'form', name: '含税总金额', key: 'taxAllPrice' },
            { type: 'form', name: '已开票金额', key: 'hasReceiptPrice' },
            { type: 'form', name: '未开票金额', key: 'unReceiptPrice' },
            { type: 'form', name: '已收款金额', key: 'hasPrice' },
            { type: 'form', name: '未收款金额', key: 'unPrice' },
            { type: 'file1', name: '订单附件', fileName: 'orderFileName', fileRealName: 'orderFileRealName', fileUrl: 'orderUrl' },
            { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'fileUrl' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '', key: 'details'
            }
          ]
        },
        {
          name: '客户开票信息',
          columns: [
            { type: 'form', name: '名称', key: 'accountName' },
            { type: 'form', name: '纳税人识别号', key: 'taxpayerNumber' },
            { type: 'form', name: '开户行', key: 'accountBank' },
            { type: 'form', name: '账号', key: 'accountNumber' },
            { type: 'form', name: '电话', key: 'invoicePhone' },
            { type: 'form', name: '地址', key: 'invoiceAddress' }

          ]
        }
      ],
      operationData: [
        // 右上角的操作按钮
        { label: '新增', perm: 'finance:otherIn:add' },
        // { label: '批量导出', perm: 'purchase:requisition:export' },
        // { label: '批量删除', perm: 'purchase:requisition:delete' },
        { label: '页面配置', perm: '' }
      ],
      typeList: []
    }
  },
  created() {
    const newData = this.$store.state.user.permissions // 看有没有编辑权限
    this.isEdit = newData.includes('finance:otherIn:edit')
    this.getDictOptions()
  },
  methods: {
    getDictOptions() {
      getDictSelects('incomeTypeCode').then(res => {
        this.typeList = res.data
      })
    },
    getExportData(data) {
      return list(data)
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    refresh2() {
      this.tableData = []
      setTimeout(() => {
        this.getList()
      }, 50)
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this) // 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    add() {
      this.$layer.iframe({
        // 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {

          } // props
        },
        area: ['1320px', '700px'],
        title: '新增附加收款单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    edit(row) {
      if (this.isEdit) {
        this.$layer.iframe({
          // 弹框
          content: {
            content: AddOrUpdate, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: {
              id: row[this.mainId]
            } // props
          },
          area: ['1320px', '700px'],
          title: '编辑附加收款单', // 标题
          shadeClose: false // 点击遮罩是否关闭
        })
      } else {
        getInfo(row.id).then(res => {
          this.$layer.iframe({// 弹框
            content: {
              content: ShowMaterialDetail, // 传递的组件对象
              parent: this, // 当前的vue对象
              data: {
                showData: res.data,
                businessId: row[this.mainId],
                showKey: this.showKey,
                isSaleOrder: true
              }// props
            },
            area: ['1320px', '700px'],
            title: '查看附加收款单', // 标题
            shadeClose: false // 点击遮罩是否关闭
          })
        })
      }
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      })
        .then(function() {
          remove(row[_this.mainId]).then(res => {
            _this.$message({
              message: res.msg,
              type: 'success'
            })
            _this.selectionsAll = []
            _this.getList()
          })
        })
        .catch(() => {})
    },
    setFileName(...data) {
      this.tableData[data[3]].fileName = data[0]
      this.tableData[data[3]].fileRealName = data[1]
      this.tableData[data[3]].fileUrl = data[2]
    },
    // 当前页的删除接口
    deleteMethod(deleteIds) {
      return remove(deleteIds)
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .accessory{
  color: #387bfc;
}
.pending_payment {
  background-color: #D1EAFF;
  color: #73c0ff;
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.under_execution {
  color: rgb(17, 109, 252);
  background-color: rgb(230, 243, 255);
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.adequate_space {
  color: #19be6b;
  background-color: rgb(223, 249, 241);
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.insufficient_space {
  color: rgb(231, 108, 108);
  background-color: rgb(255, 238, 238);
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.insufficient_space2 {
  color: rgb(255, 151, 32);
  background-color: rgb(255, 245, 239);
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.revoke_space {
  color: #999999;
  background-color: rgb(242, 242, 242);
  border-radius: 3px;
  padding: 3px 0;
  width: 80px;
  text-align: center;
}
.status_space{
  width: 100%;
  span{
    padding: 0 5px;
  }
}
</style>
